package com.qianya.oa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianya.oa.common.utils.bean.BeanUtils;
import com.qianya.oa.domain.FormDef;
import com.qianya.oa.dto.FormParam;
import com.qianya.oa.dto.FormQueryParam;
import com.qianya.oa.dto.FormUpdateParam;
import com.qianya.oa.mapper.FormDefMapper;
import com.qianya.oa.service.FormDefService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class FormDefServiceImpl implements FormDefService {

    @Resource
    private FormDefMapper formDefMapper;

    @Override
    public PageInfo<FormDef> selectFormList(FormQueryParam formQueryParam) {
        PageHelper.startPage(formQueryParam.getPageNum(), formQueryParam.getPageSize());
        List<FormDef> list = formDefMapper.selectListByLimit(formQueryParam);
        return new PageInfo<>(list);
    }


    @Override
    public int insert(FormDef record) {
        return formDefMapper.insert(record);
    }

    @Override
    public String save(FormParam formParam) {
        FormDef formDef = new FormDef();
        BeanUtils.copyProperties(formParam, formDef);
        formDef.setCreateTime(new Date());
        int i = formDefMapper.insertSelective(formDef);
        return i > 0 ? null : "新增失败";
    }

    @Override
    public String update(FormUpdateParam formUpdateParam) {
        FormDef formDef = new FormDef();
        BeanUtils.copyProperties(formUpdateParam, formDef);
        formDef.setUpdateTime(new Date());
        int i = formDefMapper.updateByPrimaryKeySelective(formDef);
        return i > 0 ? null : "修改失败";
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return formDefMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertOrUpdate(FormDef record) {
        return formDefMapper.insertOrUpdate(record);
    }

    @Override
    public int insertOrUpdateSelective(FormDef record) {
        return formDefMapper.insertOrUpdateSelective(record);
    }

    @Override
    public int insertSelective(FormDef record) {
        return formDefMapper.insertSelective(record);
    }

    @Override
    public FormDef selectByPrimaryKey(Integer id) {
        return formDefMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(FormDef record) {
        return formDefMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(FormDef record) {
        return formDefMapper.updateByPrimaryKey(record);
    }

    @Override
    public int updateBatch(List<FormDef> list) {
        return formDefMapper.updateBatch(list);
    }

    @Override
    public int batchInsert(List<FormDef> list) {
        return formDefMapper.batchInsert(list);
    }

}


